Ext.define('DragonApp.view.ban.Form', {
  extend: 'Ext.form.Panel',
  alias: ['widget.banquery'],

  requires: [
    'DragonApp.view.pub.combobox.Server',
    'DragonApp.view.pub.combobox.Channel'
  ],
  controller: 'ban',

  title: '查询表单',
  bodyPadding: 5,
  border: false,

  fieldDefaults: {
    labelWidth: 60,
    labelAlign: 'right'
  },

  items: [
    {
      xtype: 'fieldcontainer',
      layout: 'hbox',
      defaults: {
        listeners: {
          specialKey: 'onTextFieldSpecialKey'
        }
      },
      items: [
        { xtype: "servercombobox",  name: "sid",    fieldLabel: "服务器",   width: 238 },
        { xtype: "textfield",     name: "id",         fieldLabel: "玩家ID",   emptyText: '多人请用英文逗号分隔', width: 440,

              listeners:{
                'change': function(field,newValue,oldValue){
                  var noempty = DragonApp.util.String.removeAllSpace(newValue);
                  var newFieldValue = noempty.replace(/[、，;；:：\|\\/]/g, ",");
                  field.setValue(newFieldValue);
                },

                specialKey: 'onTextFieldSpecialKey'
              },
              validator: function (fieldValue) {

                //空元素处理
                var arr = fieldValue.split(',');

                //重复判断
                if(DragonApp.util.Array.repeatTest(arr)){
                  return('提示: 字段存在重复元素');
                }

                //长度判断
                for(var i=0;i<arr.length;i++){
                  if(7 != (String(arr[i])).length){
                    return('提示: '+ String(arr[i]) +' 账号长度不正确');
                  }
                  if(!DragonApp.util.Regular.Uid.test(arr[i])){
                    return('提示: 字段格式 '+ String(arr[i]) +' 不正确');
                  }
                }

                arr = arr.noEmpty();

                this.setValue(arr.join(','));
                return true;
              }
        },
        { xtype: "textfield",     name: "nickname",   fieldLabel: "玩家名",   emptyText: '多人请用英文逗号分隔', width: 440,

          listeners:{
             'change': function(field,newValue,oldValue){
                  var noemptyValue = DragonApp.util.String.removeAllSpace(newValue);
                //var newFieldValue = noemptyValue.replace(/[、，;；:：\|\\/]/g, ",");
                field.setValue(noemptyValue);
              },

             'blur': function ( field , event , eOpts ) {
                var fieldValue = field.getValue();
                var arr = fieldValue.split(',');

                arr = arr.noEmpty();

                if(DragonApp.util.Array.repeatTest(arr)){
                  DragonApp.util.Msg.showToast('提示: 玩家名字段存在重复元素');
                  return;
                }
                field.setValue(arr.join(','));
             },

             specialKey: 'onTextFieldSpecialKey'
          }

        }
      ]
    }
  ],
  buttons: [
  {
        text: '取消',
        handler: function() {
      var form = this.up('form').getForm();
      form.reset();
        }
    }, {
        text: '查询',
        formBind: true,
        disabled: true,
        handler: 'onSubmitClick'
    }
  ]
});